#include "stdafx.h"
#include <string.h>
#include "IniReader.h"
#include "Settings.h"

#ifdef _DEBUG
#include "crtdbg.h"
#endif

const TCHAR* Settings::favorite_category = NULL;
const TCHAR* Settings::email_account = NULL;
bool Settings::doMinimizeOnAction;
bool Settings::doExitOnAction;
bool Settings::doExitOnMinimize;
bool Settings::doFastGraphics;
bool Settings::useClearTypeFonts;
const TCHAR* Settings::skin_name = NULL;
bool Settings::optimizedAlpha;
bool Settings::popupAlpha;
int Settings::popupShowTime;
int Settings::popupHideTime;
int Settings::detailsSlideTime;
bool Settings::enableMouseGestures;
int Settings::mouseGesturesTime;
int Settings::scrollThresh;
int Settings::speedThresh;
int Settings::scrollBounceTime;
int Settings::scrollSearchTime;
int Settings::scrollJumpTime;
bool Settings::enableScrollAccel;
bool Settings::scrollBarContactsByLetter; // avian
bool Settings::collapseRepeatsInHistory;
int Settings::openHistoryIn;
int Settings::limitHistory;
bool Settings::showScrollIndInHistory;
bool Settings::readHistoryFromDB;
bool Settings::samsungHistoryWorkaround;
bool Settings::showRepeatsInName;
bool Settings::enableLongTapAction;
int Settings::longTapDelay;
bool Settings::drawLongTapIndicator;
bool Settings::showDialingNumber;
bool Settings::showDialNoAfterPrimaryText ;	// nocky
bool Settings::smartDialingNumber;
int Settings::openIn;
bool Settings::enableListCaching;
bool Settings::showPicturesInDetails;
bool Settings::showPicturesInList;
bool Settings::showPicturesInCallHistory;
bool Settings::enablePicturesTransparency;
bool Settings::cacheListPictures;
bool Settings::delayedPictureLoading;
bool Settings::enableFavoritesSearch;
bool Settings::showLettersInContacts;
bool Settings::showNotesInDetails;
bool Settings::showRingtonesInDetails; // lcm
bool Settings::showSimContacts;
bool Settings::delayedSimLoading;
bool Settings::highlightFavsInList;
bool Settings::showSystemTaskbar;
bool Settings::t9EnglishAsPrimary; // lcm
bool Settings::t9SearchByDefault;
bool Settings::t9SearchTransparency;
bool Settings::t9SearchByWords;
bool Settings::t9SearchByNumbers; // lcm // TODO: This might be something to remove if it is not referenced anywhere.
bool Settings::OpenSettingsOnLongTap; // avian
bool Settings::picSaveEnabled;
bool Settings::picSaveToFile;
const TCHAR* Settings::picSaveFolder;
bool Settings::picSaveToOutlook;
EPicSaveType Settings::picSaveOutlookType;
const TCHAR* Settings::smsApplication = NULL;
const TCHAR* Settings::smsApplicationArgs = NULL;
const TCHAR* Settings::mailApplication = NULL;
const TCHAR* Settings::mailApplicationArgs = NULL;
const TCHAR* Settings::dialerApplication = NULL;
const TCHAR* Settings::dialerApplicationArgs = NULL;
const TCHAR* Settings::phonePrefix = NULL;
bool Settings::showVersionInfo;
bool Settings::showDialingNumberSuffix;
bool Settings::enableUSSDStarDialing;
bool Settings::enablePhoneKeyHook;
bool Settings::callLogDetailsBackToCallLog;

bool Settings::isSmartphone = false;

void Settings::Create(HWND hWnd)
{
  email_account = IniReader::getString(IniReader::sectionMain, TEXT("EmailAccount"), TEXT("default"));

  favorite_category = IniReader::getString(IniReader::sectionMain, TEXT("FavoriteCategory"), TEXT("Favorites"));

  doMinimizeOnAction = IniReader::getBool(IniReader::sectionMain, TEXT("MinimizeOnAction"), TEXT("0"));

  doExitOnAction = IniReader::getBool(IniReader::sectionMain, TEXT("ExitOnAction"), TEXT("0"));

  doExitOnMinimize = IniReader::getBool(IniReader::sectionMain, TEXT("ExitOnMinimize"), TEXT("0"));

  doFastGraphics = IniReader::getBool(IniReader::sectionMain, TEXT("FastGraphics"), TEXT("0"));

  useClearTypeFonts = IniReader::getBool(IniReader::sectionSkin, TEXT("UseClearTypeFonts"), TEXT("1"));
  
  optimizedAlpha = IniReader::getBool(IniReader::sectionMain, TEXT("OptimizedAlpha"), TEXT("0"));

  popupAlpha = IniReader::getBool(IniReader::sectionMain, TEXT("PopupAlpha"), TEXT("1"));

  popupShowTime = IniReader::getInt(IniReader::sectionMain, TEXT("PopupShowTime"), TEXT("200"));
  popupHideTime = IniReader::getInt(IniReader::sectionMain, TEXT("PopupHideTime"), TEXT("100"));
  detailsSlideTime = IniReader::getInt(IniReader::sectionMain, TEXT("DetailsSlideTime"), TEXT("100"));

  //burt: mouse gestures begin
  enableMouseGestures = IniReader::getBool(IniReader::sectionMain, TEXT("EnableMouseGestures"), TEXT("1"));

  mouseGesturesTime = IniReader::getInt(IniReader::sectionMain, TEXT("MouseGesturesMaxTime"), TEXT("1000"));
  //burt: mouse gestures end

  scrollThresh = IniReader::getInt(IniReader::sectionMain, TEXT("ScrollThresh"), TEXT("3"));

  speedThresh = IniReader::getInt(IniReader::sectionMain, TEXT("SpeedThresh"), TEXT("6"));

  scrollBounceTime = IniReader::getInt(IniReader::sectionMain, TEXT("ScrollBounceTime"), TEXT("300"));
  scrollSearchTime = IniReader::getInt(IniReader::sectionMain, TEXT("ScrollSearchTime"), TEXT("400"));
  scrollJumpTime = IniReader::getInt(IniReader::sectionMain, TEXT("ScrollJumpTime"), TEXT("50"));

  enableScrollAccel = IniReader::getBool(IniReader::sectionMain, TEXT("EnableScrollAcceleration"), TEXT("1"));
  scrollBarContactsByLetter = IniReader::getBool(IniReader::sectionMain, TEXT("ScrollBarContactsByLetter"), TEXT("1"));

  collapseRepeatsInHistory = IniReader::getBool(IniReader::sectionMain, TEXT("CollapseRepeatsInHistory"), TEXT("1"));
  openHistoryIn = IniReader::getInt(IniReader::sectionMain, TEXT("OpenHistoryIn"), TEXT("0"));
  limitHistory = IniReader::getInt(IniReader::sectionMain, TEXT("LimitHistory"), TEXT("0"));
  showScrollIndInHistory = IniReader::getBool(IniReader::sectionMain, TEXT("ShowScrollIndInHistory"), TEXT("0"));
  readHistoryFromDB = IniReader::getBool(IniReader::sectionMain, TEXT("ReadHistoryFromDB"), TEXT("1"));
  samsungHistoryWorkaround = IniReader::getBool(IniReader::sectionMain, TEXT("SamsungHistoryWorkaround"), TEXT("0"));
  showRepeatsInName = IniReader::getBool(IniReader::sectionMain, TEXT("ShowRepeatsInName"), TEXT("0"));

  enableLongTapAction = IniReader::getBool(IniReader::sectionMain, TEXT("EnableLongTapAction"), TEXT("1"));
  longTapDelay = IniReader::getInt(IniReader::sectionMain, TEXT("LongTapDelay"), TEXT("1500"));
  if (longTapDelay == 0)
    longTapDelay = 1500;
  drawLongTapIndicator = IniReader::getBool(IniReader::sectionMain, TEXT("ShowLongTapIndicator"), TEXT("1"));

  showDialingNumber = IniReader::getBool(IniReader::sectionMain, TEXT("ShowDialingNumber"), TEXT("1"));
  showDialNoAfterPrimaryText = IniReader::getBool(IniReader::sectionMain, TEXT("showDialNoAfterPrimaryText"), TEXT("1"));
  smartDialingNumber = IniReader::getBool(IniReader::sectionMain, TEXT("SmartDialingNumber"), TEXT("0"));

  openIn = IniReader::getInt(IniReader::sectionMain, TEXT("OpenIn"), TEXT("2"));

  enableListCaching = IniReader::getBool(IniReader::sectionMain, TEXT("EnableListCaching"), TEXT("1"));

  showPicturesInDetails = IniReader::getBool(IniReader::sectionMain, TEXT("ShowPicturesInDetails"), TEXT("1"));
  showPicturesInList = IniReader::getBool(IniReader::sectionMain, TEXT("ShowPicturesInList"), TEXT("1"));
  showPicturesInCallHistory = IniReader::getBool(IniReader::sectionMain, TEXT("ShowPicturesInCallHistory"), TEXT("0"));
  enablePicturesTransparency = IniReader::getBool(IniReader::sectionMain, TEXT("EnablePicturesTransparency"), TEXT("1"));
  cacheListPictures = IniReader::getBool(IniReader::sectionMain, TEXT("CacheListPictures"), TEXT("1"));
  delayedPictureLoading = IniReader::getBool(IniReader::sectionMain, TEXT("DelayedPictureLoading"), TEXT("1"));

  enableFavoritesSearch = IniReader::getBool(IniReader::sectionMain, TEXT("EnableFavoritesSearch"), TEXT("1"));
  showLettersInContacts = IniReader::getBool(IniReader::sectionMain, TEXT("ShowLettersInContacts"), TEXT("1"));

  showNotesInDetails = IniReader::getBool(IniReader::sectionMain, TEXT("ShowNotesInDetails"), TEXT("1"));
  showRingtonesInDetails = IniReader::getBool(IniReader::sectionMain, TEXT("ShowRingtonesInDetails"), TEXT("1"));

  showSimContacts = IniReader::getBool(IniReader::sectionMain, TEXT("ShowSimContacts"), TEXT("0"));
  delayedSimLoading = IniReader::getBool(IniReader::sectionMain, TEXT("DelayedSimLoading"), TEXT("1"));

  highlightFavsInList = IniReader::getBool(IniReader::sectionMain, TEXT("HighlightFavoritesInList"), TEXT("0"));

  showSystemTaskbar = IniReader::getBool(IniReader::sectionMain, TEXT("ShowSystemTaskbar"), TEXT("0"));

  t9EnglishAsPrimary = IniReader::getBool(IniReader::sectionMain, TEXT("T9EnglishAsPrimary"), TEXT("0"));
  t9SearchByDefault = IniReader::getBool(IniReader::sectionMain, TEXT("T9SearchByDefault"), TEXT("0"));
  t9SearchTransparency = IniReader::getBool(IniReader::sectionMain, TEXT("T9SearchTransparent"), TEXT("0"));
  t9SearchByWords = IniReader::getBool(IniReader::sectionMain, TEXT("T9SearchByWords"), TEXT("0"));
  t9SearchByNumbers = IniReader::getBool(IniReader::sectionMain, TEXT("T9SearchByNumbers"), TEXT("0"));

  picSaveEnabled = IniReader::getBool(IniReader::sectionMain, TEXT("PicSaveEnabled"), TEXT("1"));
  picSaveToFile = IniReader::getBool(IniReader::sectionMain, TEXT("PicSaveToFile"), TEXT("0"));
  picSaveFolder = IniReader::getString(IniReader::sectionMain, TEXT("PicSaveFolder"), TEXT("Caller Pictures"));
  picSaveToOutlook = IniReader::getBool(IniReader::sectionMain, TEXT("PicSaveToOutlook"), TEXT("1"));
  int picSaveType = IniReader::getInt(IniReader::sectionMain, TEXT("PicSaveOutlookType"), TEXT("0"));
  if (picSaveType >= pstFirst && picSaveType <= pstLast)
    picSaveOutlookType = (EPicSaveType)picSaveType;
  else
    picSaveOutlookType = pstDefault;

  smsApplication = IniReader::getString(IniReader::sectionMain, TEXT("SmsApplication"), TEXT(""));
  smsApplicationArgs = IniReader::getString(IniReader::sectionMain, TEXT("SmsApplicationArgs"), TEXT(""));
  mailApplication = IniReader::getString(IniReader::sectionMain, TEXT("MailApplication"), TEXT(""));
  mailApplicationArgs = IniReader::getString(IniReader::sectionMain, TEXT("MailApplicationArgs"), TEXT(""));
  dialerApplication = IniReader::getString(IniReader::sectionMain, TEXT("DialerApplication"), TEXT(""));
  dialerApplicationArgs = IniReader::getString(IniReader::sectionMain, TEXT("DialerApplicationArgs"), TEXT(""));

  phonePrefix = IniReader::getString(IniReader::sectionMain, TEXT("PhonePrefix"), TEXT(""));

  skin_name = IniReader::getString(IniReader::sectionMain, TEXT("Skin"), TEXT("default"));

  showVersionInfo = IniReader::getBool(IniReader::sectionMain, TEXT("ShowVersionInfo"), TEXT("1"));

  showDialingNumberSuffix = IniReader::getBool(IniReader::sectionMain, TEXT("ShowDialingNumberSuffix"), TEXT("1"));

  enableUSSDStarDialing = IniReader::getBool(IniReader::sectionMain, TEXT("EnableUSSDStarDialing"), TEXT("0"));

  enablePhoneKeyHook = IniReader::getBool(IniReader::sectionMain, TEXT("EnablePhoneKeyHook"), TEXT("1"));

  callLogDetailsBackToCallLog = IniReader::getBool(IniReader::sectionMain, TEXT("CallLogDetailsBackToCallLog"), TEXT("1"));

  OpenSettingsOnLongTap = IniReader::getBool(IniReader::sectionMain, TEXT("OpenSettingsOnLongTap"), TEXT("1"));

  // detect platform type
  TCHAR szPlatform[256] = { 0 };
  if (SystemParametersInfo(SPI_GETPLATFORMTYPE, 256, szPlatform, 0))
  {
    isSmartphone = (_tcsicmp(szPlatform, TEXT("Smartphone")) == 0);
  }
  else
  { // Smartphone creates an access denied error on SystemParametersInfo
    if (GetLastError() == ERROR_ACCESS_DENIED)
      isSmartphone = true;
  }
}

void Settings::Destroy(void)
{
}
